package com.omenkk.juc.synchronizedPlus;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Mailboxes {


    private static Map<Integer,GuardedObject> map=new HashMap<>();
    private static int id=1;
    private static synchronized int generateId(){
        return id++;
    }
    public  static GuardedObject createGuarded(){
        GuardedObject guardedObject=new GuardedObject(generateId());
        map.put(guardedObject.getId(),guardedObject);
        return guardedObject;
    }

    public static GuardedObject getGuarder(int id){
        return map.remove(id);
    }

    public static Set<Integer> getIds(){
        return map.keySet();
    }
}
